<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>i18n 上传</title>
    <meta name="keywords" content="i18n 上传">
    <meta name="description" content="i18n上传">

    <link href="<?= base_url('assets/css/bootstrap.min.css?v=3.3.6') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/font-awesome.css?v=4.4.0') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/animate.css') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>i18n上传</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" method="post"   id="uploadForm" enctype=”multipart/form-data” >
                        <div class="form-group">
                            <label class="col-sm-3 control-label">版本号：</label>
                            <div class="col-sm-8">
                                <input id="version" name="version" minlength="2" type="number" class="form-control" required="" aria-required="true">
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">平台：</label>

                            <div class="col-sm-8" >

                                <div class="radio" style="float:left;">
                                    <input type="radio" checked="" value="21" id="type_ios" name="appid">IOS
                                </div>
                                <div class="radio" style="margin-left: 100px" >
                                    <input type="radio" value="22" id="type_android" name="appid">Android
                                </div>
                            </div>
                        </div>



                        <div class="form-group">
                            <label for="lastname" class="control-label col-lg-3">i18n文件</label>
                            <div class="col-lg-9">
                                <input type="file"  name="i18n_file" id="i18n_file" onchange ="">
                                <p class="help-block">上传文件</p>
                                <div class="files"></div>
                                <div class="progress">
                                    <div id="progress" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100"></div>
                                </div>
                            </div>
                        </div>



                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="button" onclick="uploadFile()">保存</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>


        </div>


    </div>

</div>

<?php include "include/admin_foot_script.php" ?>

<!-- Data Tables -->

<link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">
<!-- 自定义js -->
<script src="<?= base_url('assets/js/content.js?v=1.0.0') ?>"></script>

<script src="<?= base_url('assets/js/plugins/layer/layer.min.js') ?>"></script>

<script src="<?= base_url('assets/js/jquery.form.min.js') ?>"></script>

<script>

    function onReset() {
        $("#uploadForm")[0].reset();
        $("#sp_fail").html("")
        $("#progress").width('0');
        $(".files").html("");
    }


    function uploadFile() {

        var files = $(".files");
        $("#sp_fail").html("")
        var progWrap = $(".progress");
        var progress = $("#progress");
        progress.width('0');


        var file = $("#i18n_file").val();
        var version = $("#version").val();
        var appid = $("input[name='appid']:checked").val();
        $("#uploadForm").ajaxSubmit({
            url: '<?= base_url("admin/app/i18n/upload") ?>',
            dataType: 'json',
            data: {
                "version":version,
                "appid": appid
            },
            beforeSend: function() {
                progWrap.show(); //显示进度条
                var percentVal = '0%';
                progress.width(percentVal);
            },
            uploadProgress: function(event, position, total, percentComplete) {
                var percentVal = percentComplete + '%'; //获得进度
                progress.width(percentVal); //上传进度条宽度变宽
            },
            success: function(data) {

                if (data.code == 200) {
                    files.html("<b>"+data.name+"("+data.size+"M)</b>");
                    toastr.success("上传i18n文件成功", '提示');
                    window.location.href = "<?= base_url("admin/app/i18n") ?>";
                } else {
                    toastr.error(data.msg, '提示');
                    progress.width('0');
                }

            },
            error:function(xhr){
                progress.width('0');
                files.html(xhr.responseText);
            }
        });
    }

</script>
</body>
</html>